package xyz.lilei123;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * @author jack
 * @version 1.0
 * @date 28/11/2021 21:20
 **/
public class testRedis {


    public static void main(String[] args) {

        Set<HostAndPort> jedisClusterNodes = new HashSet<>();
        String host = "192.168.168.14";
        //添加集群节点
        jedisClusterNodes.add(new HostAndPort(host,7000));
        jedisClusterNodes.add(new HostAndPort(host,7001));
        jedisClusterNodes.add(new HostAndPort(host,7002));
        jedisClusterNodes.add(new HostAndPort(host,7003));
        jedisClusterNodes.add(new HostAndPort(host,7004));
        jedisClusterNodes.add(new HostAndPort(host,7005));
        jedisClusterNodes.add(new HostAndPort(host,7007));
        jedisClusterNodes.add(new HostAndPort(host,7008));

        //获取集群连接
        JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, new JedisPoolConfig());

        //设置值
        jedisCluster.set("name:002","jack");

        //获取值
        System.out.println(jedisCluster.get("name:002"));
        try {
            jedisCluster.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
